package henu.util;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import henu.bean.Teacher;


public class GetExcelInfosutl {
	/**
     * 得到成绩excel所有的信息
     * @param file 
     * @return Excel中所有的信息
	 * @throws IOException 
	 * @throws InvalidFormatException 
     */
	@SuppressWarnings("deprecation")
	
	public static List<Teacher> getAllByExcel(File filepath){
		System.out.println("getAllByExcel");
		List<Teacher> list=new ArrayList<Teacher>();
			
			Workbook rwb = null;
		
			
		//	rwb = WorkbookFactory.create(filepath);
		
			System.out.println(1);
			Sheet sheet = rwb.getSheetAt(0);
			int rowNum = sheet.getPhysicalNumberOfRows();
			int rows = sheet.getLastRowNum();
			System.out.println("rowNum"+rowNum+"  lastRow "+rows);
			for(int i = 1; i <= rows; i++){			   
				Teacher tea = new Teacher();
				Row row = sheet.getRow(i);
				tea.setfTeacherId(row.getCell(0).getStringCellValue());    
				tea.setfTeachName(row.getCell(1).getStringCellValue());  
				tea.setfJobTitle(row.getCell(2).getStringCellValue());  
				tea.setfDept(row.getCell(3).getStringCellValue()); 
				tea.setfPhoneNumber(row.getCell(4).getStringCellValue());
				tea.setfEmail(row.getCell(5).getStringCellValue());
				tea.setfQQ(row.getCell(6).getStringCellValue());
				tea.setfMemo(row.getCell(7).getStringCellValue());
			   
			   	list.add(tea);
			}
			System.out.println("list.size"+list.size());
			
			return list;
	
		
	
	}  
}
